 package com.kmproject.haifu.mvp.presenter;

import android.app.Application;

import com.jess.arms.integration.AppManager;
import com.jess.arms.di.scope.ActivityScope;
import com.jess.arms.mvp.BasePresenter;
import com.jess.arms.http.imageloader.ImageLoader;

import io.reactivex.Observable;
import me.jessyan.rxerrorhandler.core.RxErrorHandler;
import me.jessyan.rxerrorhandler.handler.ErrorHandleSubscriber;

import javax.inject.Inject;

import com.kmproject.haifu.app.utils.AppUtil;
import com.kmproject.haifu.app.utils.RxUtils;
import com.kmproject.haifu.mvp.contract.UserSetEditInfoSetTxtContract;
import com.kmproject.haifu.mvp.model.entity.ResultBean;


 /**
 * ================================================
 * Description:
 * <p>
 * Created by MVPArmsTemplate on 06/24/2019 13:58
 * <a href="mailto:jess.yan.effort@gmail.com">Contact me</a>
 * <a href="https://github.com/JessYanCoding">Follow me</a>
 * <a href="https://github.com/JessYanCoding/MVPArms">Star me</a>
 * <a href="https://github.com/JessYanCoding/MVPArms/wiki">See me</a>
 * <a href="https://github.com/JessYanCoding/MVPArmsTemplate">模版请保持更新</a>
 * ================================================
 */
@ActivityScope
public class UserSetEditInfoSetTxtPresenter extends BasePresenter<UserSetEditInfoSetTxtContract.Model, UserSetEditInfoSetTxtContract.View> {
    @Inject
    RxErrorHandler mErrorHandler;
    @Inject
    Application mApplication;
    @Inject
    ImageLoader mImageLoader;
    @Inject
    AppManager mAppManager;

    @Inject
    public UserSetEditInfoSetTxtPresenter(UserSetEditInfoSetTxtContract.Model model, UserSetEditInfoSetTxtContract.View rootView) {
        super(model, rootView);
    }

     /**
      * 设置性别
      * @param updUserSex
      */
     public void updUserSex(String updUserSex) {
         mModel.updUserSex(updUserSex).compose(RxUtils.applySchedulers(mRootView))
                 .subscribe(new ErrorHandleSubscriber<ResultBean>(mErrorHandler) {
                     @Override
                     public void onNext(ResultBean resultBean) {
                         if (AppUtil.isSuccess(resultBean))
                         {
                             mRootView.showMessage("性别设置成功");
                             mRootView.updateSuccess();
                         }else {
                             mRootView.showMessage(resultBean.getMessage());
                         }

                     }
                 });
     }
     /**
      * 设置个性签名
      * @param userDesc
      */
     public void updateUserDesc(String userDesc) {
         mModel.updateUserDesc(userDesc).compose(RxUtils.applySchedulers(mRootView))
                 .subscribe(new ErrorHandleSubscriber<ResultBean>(mErrorHandler) {
                     @Override
                     public void onNext(ResultBean resultBean) {
                         if (AppUtil.isSuccess(resultBean))
                         {
                             mRootView.showMessage("个性签名设置成功");
                             mRootView.updateSuccess();
                         }else {
                             mRootView.showMessage(resultBean.getMessage());
                         }

                     }
                 });
     }


     /**
      * 设置昵称
      * @param nickName
      */
     public void  updateUserNickName(String nickName) {
        mModel.updateUserNickName(nickName).compose(RxUtils.applySchedulers(mRootView))
                .subscribe(new ErrorHandleSubscriber<ResultBean>(mErrorHandler) {
                    @Override
                    public void onNext(ResultBean resultBean) {
                        if (AppUtil.isSuccess(resultBean))
                        {
                            mRootView.showMessage("昵称设置成功");
                            mRootView.updateSuccess();
                        }else {
                            mRootView.showMessage(resultBean.getMessage());
                        }

                    }
                });
     }
    @Override
    public void onDestroy() {
        super.onDestroy();
        this.mErrorHandler = null;
        this.mAppManager = null;
        this.mImageLoader = null;
        this.mApplication = null;
    }
}
